import { NextRequest, NextResponse } from 'next/server';

export function middleware(request: NextRequest): NextResponse {

  let flag = false
 // 从请求头中获取 cookies
 const token = request.cookies.get('Backstage-Token'); 
  if (!token) {
    return NextResponse.redirect(new URL('/login', request.url))
  }

  // 获取请求路径
  // const { pathname } = request.nextUrl;
  // // 示例：如果路径是 `/admin`，重定向到 `/login`
  // if (pathname.startsWith('/about')) {
  //   // return NextResponse.redirect(new URL('/pages/login', request.url));
  // }

  // 默认继续请求
  return NextResponse.next();
}


export const config = {
  matcher: ['/pages/:path*','/'],  // 只在这些路径下运行中间件
};  